#=
    support use of TimeZones package with UniversalTime and LocalTime
=#

import TimeZones: ZonedDateTime, TimeZone, astimezone, localzone, @tz_str

const tzUniversal = tz"UTC"
const tzLocal = localzone()

isuniversaltime(x::ZonedDateTime) = x.timezone == tzUniversal
islocaltime(x::ZonedDateTime) = x.timezone == tzLocal

function UniversalTime(x::ZonedDateTime)
    y = astimezone(x, tzUniversal)
    return UniversalTime(DateTime(y))
end

function LocalTime(x::ZonedDateTime)
    y = astimezone(x, tzLocal)
    return LocalTime(DateTime(y))
end

function astimezone(x::UniversalTime, tz::TimeZone)
    y = DateTime(x)
    z = ZonedDateTime(y, tzUniversal)
    return astimezone(z, tz)
end

function astimezone(x::LocalTime, tz::TimeZone)
    y = DateTime(x)
    z = ZonedDateTime(y, tzLocal)
    return astimezone(z, tz)
end

function astimezone(x::Clock, tz::TimeZone)
    y = DateTime(x)
    return ZonedDateTime(y, tz)
end

astimezone(x::UniversalTime) = astimezone(x, tzUniversal)
astimezone(x::LocalTime) = astimezone(x, tzLocal)

ZonedDateTime(x::UniversalTime) = astimezone(x)
ZonedDateTime(x::LocalTime) = astimezone(x)
